//house keeping:  develop methods for der
//gets variable where I need them (globals)
import java.awt.Graphics;
import java.awt.Image;
import java.util.Random;

public class BJ7 extends java.applet.Applet
{

	Image [] Player1pic= new Image [5] ;
	Image [] Player2pic= new Image [5] ;
	int [] hearts = new int [13]; // this does an array
	int [] diamonds = new int [13];
	int [] clubs = new int [13];
	int [] spades = new int [13];
	String card=" ";
	int [] player1=new int[5];
	int [] player2=new int[5];
	String [] Player1Cards=new String[5];
	String [] Player2Cards=new String[5];


	String suit=" ";
	String value=" ";
	Random Generate1= new Random();
	int  x;
	int  y;
	int OK=1;

	public void init()
	{
	int i;
    for ( i=0; i<5; i++)  //picks 5 unique cards for player1
	{
		do
		{
			card=card_maker();  //calls the next method card_maker
			OK=notAlreadyPicked();

		}while(OK == 0);
		Player1pic[i] = getImage(getCodeBase(),card); //mypic does make it to repaint
	    Player1Cards[i]=card;
		System.out.println(Player1Cards[i]);
	}
	for (i=0; i<5; i++)  //picks 5 unique cards for player2
	{
		do
		{
			card=card_maker();  //calls the next method card_maker
			OK=notAlreadyPicked();
			Player2pic[i] = getImage(getCodeBase(),card); //mypic does make it to repaint
		}while(OK == 0);
		Player2pic[i] = getImage(getCodeBase(),card);
	    Player2Cards[i]=card;
	}
	}
	public String card_maker()  //returns a possible card string (picture file)
	{//variables in init are not sent down to here



	y=(int)(Generate1.nextDouble()*13)+1;
	x=(int)(Generate1.nextDouble()*4)+1; //4because 4 suits
	if (x==1)
		suit="H"; //suit is hearts
	if (x==2)
		suit="D"; //suit is diamonds
	if (x==3)
		suit="C"; //suit is clubs
	if (x==4)
		suit="S"; //suit is spades
	if(y==1)
		value="01";
	if(y==2)
		value="02";
	if(y==3)
		value="03";
	if(y==4)
		value="04";
	if(y==5)
		value="05";
	if(y==6)
		value="06";
	if(y==7)
		value="07";
	if(y==8)
		value="08";
	if(y==9)
		value="09";
	if(y==10)
		value="10";
	if(y==11)
		value="11";
	if(y==12)
		value="12";
	if(y==13)
		value="13";
	card=suit+value + ".jpg";
	return card;
	}
	public int notAlreadyPicked() //selects a unique card
	{

		if (suit=="C")
		{
			if (clubs[y-1] != 1)//this card is a good choice
			{
				clubs[y-1] =1;
				OK =1;
			}
		    else
			{
				OK=0;
			}
		}
		if (suit=="H")
		{
			if (hearts[y-1] != 1) //this card is a good choice
			{
				hearts[y-1] =1;
				OK =1;
			}
		    else
			{
				OK=0;
			}
		}
		if (suit=="S")
		{
			if (spades[y-1] != 1)  //this card is a good choice
			{
				spades[y-1] =1;
				OK =1;
			}
		    else
			{
				OK=0;
			}
		}
		if (suit=="D")
		{
			if (diamonds[y-1] != 1)  //this card is a good choice
			{
				diamonds[y-1] =1;
				OK =1;
			}
		    else
			{
				OK=0;
			}
		}
		return OK;
	}
	public void paint(Graphics screen)
	{

		int	iWidth =71 ;//71 pixelsPlayer1pic[0].getWidth(this);
		int iHeight=96;  //96 pixelsPlayer1pic[0].getHeight(this);
		int xPos=0 ;
		for (int i=0; i<5; i++)
		{
		   screen.drawImage(Player1pic[i], i*(iWidth+10),10, this);
		   screen.drawImage(Player2pic[i], i*(iWidth+10), 250, this);
		   Reshuffle();

		}
	}
	public void Reshuffle() //can only go 5 times without zeroing things
	{
		for (int i=0; i<5;i++)
		{
			clubs[i]=0;
			spades[i]=0;
			diamonds[i]=0;
			hearts[i]=0;

		}

	}

}
